#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>

int make_socket(uint16_t port)
{
    struct sockaddr_in addr;

    int sock = socket(PF_INET, SOCK_STREAM, 0);
    if (sock < 0)
    {
        perror("socket");
        exit(EXIT_FAILURE);
    }

    // 绑定端口
    addr.sin_family = AF_INET;
    addr.sin_port = htonl(port);
    // 通配地址
    addr.sin_addr.s_addr = htonl(INADDR_ANY);

    //socket和地址管理
    if (bind(sock, (struct sockaddr *)&addr, sizeof(addr) < 0))
    {
        perror("bind error");
        exit(EXIT_FAILURE);
    }
    // listen
    // accept
    // connect

    return sock;
}